package com.qilu.careprogram.service.impl;

import com.qilu.careprogram.dao.UserQuestionDAO;
import com.qilu.careprogram.pojo.dto.AnsQueDTO;
import com.qilu.careprogram.pojo.dto.AnswerDTO;
import com.qilu.careprogram.pojo.dto.UserQuestionDTO;
import com.qilu.careprogram.pojo.entity.UserQuestion;
import com.qilu.careprogram.pojo.vo.QuestionVO;
import com.qilu.careprogram.service.QuestionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {

    @Resource
    UserQuestionDAO userQuestionDAO;

    @Override
    public void insert(UserQuestionDTO userQuestionDTO) {
        UserQuestion userQuestion = UserQuestion.builder()
                .hospitalNumber(userQuestionDTO.getHospitalNumber())
                .question(userQuestionDTO.getQuestion())
                .isProcessed(false)
                .isDeleted(false)
                .createTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build();
        userQuestionDAO.insert(userQuestion);
    }

    @Override
    public List<QuestionVO> getUnprocessedQuestion() {
        return userQuestionDAO.getUnprocessedQuestion();
    }

    @Override
    public void processQuestion(Long id) {
        userQuestionDAO.processQuestion(id);
    }

    @Override
    public void deleteQuestion(Long id) {
        userQuestionDAO.deleteQuestion(id);
    }

    @Override
    public void processQuestion(AnswerDTO answerDTO) {
        UserQuestion userQuestion = UserQuestion.builder()
                .id(answerDTO.getId())
                .answer(answerDTO.getAnswer())
                .build();
        userQuestionDAO.update(userQuestion);
    }

    @Override
    public List<QuestionVO> getAllQuestion() {
        return userQuestionDAO.getAllQuestion();
    }

    @Override
    public void insert(AnsQueDTO ansQueDTO) {
        UserQuestion userQuestion = UserQuestion.builder()
                .question(ansQueDTO.getQuestion())
                .answer(ansQueDTO.getAnswer())
                .isProcessed(true)
                .isDeleted(false)
                .createTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build();
        userQuestionDAO.insert(userQuestion);
    }
}
